<?php

namespace app\admin\controller;

use app\admin\model\Activity;
use app\admin\model\MenuRule;
use app\admin\model\PrizeRecord;
use app\common\controller\Backend;
use app\common\model\AnswerSheet;
use app\common\model\Information;
use app\common\model\Organize;
use app\common\model\Project;
use app\common\model\SmsRecord;
use app\common\model\User;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\facade\Config;

/**
 * 控制台数据
 */
class Console extends Backend
{
    /**
     * 不验证菜单权限
     * @var string[]
     */
    protected $noNeedPermission = [];

    public function index()
    {
        $menuList = array();
        $day      = 14; // 代表近几天的数据(例如：7则为7-1)
        $time     = time(); // 当前时间戳
        $startTime= strtotime(date("Y-m-d", ($time - ($day * 86400) ) )); // 开始时间戳
        $endTime  = strtotime(date("Y-m-d 23:59:59", $time)); // 结束时间戳
        try {
            $ruleIds = $this->auth->getRuleIds(); // 当前登录用户的权限ID
            // 查询快捷菜单列表
            $where = array();
            if ($ruleIds[0] !== '*') {
                $where[] = ['id', 'IN', $ruleIds];
            }
            $where[]       = ['is_quick', '=', 1];
            $menuRuleModel = new MenuRule();
            $menuList      = $menuRuleModel->field("title,icon,path")
                ->where($where)
                ->order("weigh", "DESC")
                ->select()
                ->toArray();
            unset($ruleIds);
        } catch (DataNotFoundException|DbException $e) {
        }
        $version = Config::get("backstage.version"); // 获取系统版本
        $this->success('', [
            'menuList'            => $menuList,
            'version'             => $version,
            'site_name'           => get_sys_config('site_name'),
            'php_version'         => PHP_VERSION,
            'user_total'          => 0,
            'project_total'       => 0,
            'organize_total'      => 0,
            'information_total'   => 0,
            'prize_record_total'  => 0,
            'sms_record_total'    => 0,
            'activity_total_list' => 0,
        ]);
    }
}